Lifecycle methods are available to class based components:
constructor
static getDerivedStateFromProps
render()
componentDidMount
getSnapshotBeforeUpdate
shouldComponentUpdate
componentDidUpdate -> after the component updates
componentWillUnmount() → cleanup when the component is unmounting
componentDidCatch
How would you add a console.log to see when a component mounts and when it unmounts?
Which lifecycle method runs right after the first render, and what is it typically used for?
What happens if you call setState inside componentWillUnmount?
Your component fetches data in componentDidMount but you notice the request fires twice. Which lifecycle methods would you inspect to fix it?
A child component re‑renders on every parent prop change even though it doesn’t need the new data. Which lifecycle method could you implement to prevent the extra renders?
You’re replacing componentWillReceiveProps with getDerivedStateFromProps. What changes are required and what pitfalls should you watch for?
Design a reusable error‑boundary component. Which lifecycle methods are essential and how do they interact with React’s error handling?
You need a polling loop that starts on mount, stops on unmount, and pauses when the browser tab is hidden. Which lifecycle methods or hooks would you use and why?
When optimizing a large list, how would you decide between using componentDidUpdate versus getSnapshotBeforeUpdate to measure DOM changes?
Your organization is migrating 200 class components to functional components with hooks. How would you plan the migration, ensuring lifecycle behavior stays equivalent and regressions are caught?
Across several teams you need a consistent strategy for side‑effects and cleanup. What guidelines would you set for using useEffect versus class lifecycle methods, and how would you enforce them?
If you must support both React 16.8 (with hooks) and older versions without hooks, how would you architect shared components to expose lifecycle behavior without duplicating code?